﻿using System.IO;
using Framework.Core.Io;
using Xunit;

namespace Framework.Tests.Core.Io
{
    public class IoAdapterTest
    {
        private const string TestFile = @".\titi.txt";
        private const string TestDir = @".\TestDir";

        static IoAdapterTest()
        {
            if (!File.Exists(TestFile))
            {
                using (var file = File.Open(TestFile, FileMode.Create, FileAccess.Write))
                using (var writer = new StreamWriter(file))
                {
                    writer.WriteLine("hello");
                }
            }

            if (!Directory.Exists(TestDir))
            {
                Directory.CreateDirectory(TestDir);
            }
        }

        private readonly IIoAdapter ioAdapter = new IoAdapter();

        [Fact]
        public void Should_return_false_if_file_not_exists()
        {
            Assert.False(ioAdapter.FileExists(@".\toto.txt"));
        }

        [Fact]
        public void Should_return_true_if_file_exists()
        {
            Assert.True(ioAdapter.FileExists(TestFile));
        }

        [Fact]
        public void Should_get_directory_fullname()
        {
            Assert.Equal(@"c:\temp", ioAdapter.GetFileDirectory(@"c:\temp\toto.txt"));
        }

        [Fact]
        public void Should_return_false_if_directory_does_not_exists()
        {
            Assert.False(ioAdapter.DirectoryExists(@"c:\kjgdjkgsd"));
        }

        [Fact]
        public void Should_return_true_if_directory__exists()
        {
            Assert.True(ioAdapter.DirectoryExists(TestDir));
        }
    }
}
